home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pavt150.zip / CAPI.ZIP / JAMFIELD.C < prev    next >
C/C++ Source or Header  |  1993-07-01  |  3KB  |  91 lines

  1. /*
  2. **  JAM(mbp) - The Joaquim-Andrew-Mats Message Base Proposal
  3. **
  4. **  C API
  5. **
  6. **  Written by Joaquim Homrighausen.
  7. **
  8. **  ----------------------------------------------------------------------
  9. **
  10. **  jamfield.c (JAMmb)
  11. **
  12. **  Subfield functions
  13. **
  14. **  Copyright 1993 Joaquim Homrighausen, Andrew Milner, Mats Birch, and
  15. **  Mats Wallin. ALL RIGHTS RESERVED.
  16. **
  17. **  93-06-28    JoHo
  18. **  Initial coding. No decryption or unescaping supported yet.
  19. */
  20. #define JAMCAPI 1
  21.  
  22. #include "jammb.h"
  23. #include <string.h>
  24.  
  25. /*
  26. **  Find specified field in passed buffer. It requires that POSITION has
  27. **  been reset to zero (0) prior to the first call. the POSITION parameter
  28. **  is updated to point to the beginning of the found field.
  29. **  Returns 1 if the field is found and 0 if the field is not found.
  30. */
  31. int _JAMPROC JAMmbFindField(JAMAPIRECptr apirec, UINT32 WhatField, UINT32ptr Position)
  32. {
  33.     *Position=JAMsysAlign(*Position);
  34.     while (1)
  35.         {
  36.         apirec->SubFieldPtr=(JAMSUBFIELD *) JAMsysAddPtr(apirec->WorkBuf, *Position);
  37.         if (apirec->SubFieldPtr->LoID==(UINT16)WhatField)
  38.             /* Found it */
  39.             return (1);
  40.         else
  41.             /* Get next subfield */
  42.             {
  43.             *Position+=(apirec->SubFieldPtr->DatLen+(UINT32)sizeof(JAMSUBFIELD));
  44.             *Position=JAMsysAlign(*Position);
  45.             if (*Position>=apirec->WorkLen)
  46.                 return (0);
  47.             }
  48.         }/*while*/
  49.  
  50.     /* Dummy return to avoid warnings from some compilers */
  51.     return (0);
  52. }
  53.  
  54. /*
  55. **  Add specified field to WorkBuf. It requires that POSITION has been
  56. **  reset to zero (0) prior to the first call. The POSITION parameter is
  57. **  updated to point to the first position after the newly added field.
  58. **  The FIRST parameter determines if the DatLen/ID fields should be
  59. **  copied. This allows multiple calls to this function to add more than
  60. **  64kb to a subfield. Returns 1 on success or 0 if the requested field
  61. **  does not fit into WorkBuf
  62. */
  63. int _JAMPROC JAMmbAddField(JAMAPIRECptr apirec, UINT32 WhatField,
  64.                             int First, unsigned int DatLen,
  65.                             UINT32ptr Position, CHAR8ptr Data)
  66. {
  67.     if (First)
  68.         {
  69.         *Position=JAMsysAlign(*Position);
  70.         if (((UINT32)sizeof(JAMBINSUBFIELD)+(*Position)+DatLen)>apirec->WorkLen)
  71.             return (0);
  72.         apirec->SubFieldPtr=(JAMSUBFIELD *)JAMsysAddPtr(apirec->WorkBuf,*Position);
  73.         apirec->SubFieldPtr->LoID=(UINT16)WhatField;
  74.         apirec->SubFieldPtr->HiID=0;
  75.         apirec->SubFieldPtr->DatLen=0L;
  76.         *Position+=(UINT32)sizeof(JAMBINSUBFIELD);
  77.         }
  78.     else
  79.         {
  80.         if ((DatLen+(*Position))>apirec->WorkLen)
  81.             return (0);
  82.         }
  83.  
  84.     memcpy(JAMsysAddPtr(apirec->WorkBuf,*Position), Data, DatLen);
  85.     apirec->SubFieldPtr->DatLen+=DatLen;
  86.     *Position+=(UINT32)DatLen;
  87.     return (1);
  88. }
  89.  
  90. /* end of file "jamfield.c" */
  91.